package com.daocheng.dc.book.auth.rpc;

import com.daocheng.dc.book.user.api.UserFeignApi;
import com.daocheng.dc.book.user.dto.req.FindByPhoneReqDTO;
import com.daocheng.dc.book.user.dto.req.RegisterUserReqDTO;
import com.daocheng.dc.book.user.dto.req.UpdatePasswordReqDTO;
import com.daocheng.dc.book.user.dto.rsp.FindByPhoneRspDTO;
import com.daocheng.framework.common.response.Response;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @ClassName UserRpcService
 * @author: 稻城
 * @date: 2025/3/31
 * @Version 1.0
 * @description: TODO
 */
@Component
public class UserRpcService {
    @Resource
    private UserFeignApi userFeignApi;

    public Long registerUser(String phone) {
        RegisterUserReqDTO registerUserReqDTO = new RegisterUserReqDTO();
        registerUserReqDTO.setPhone(phone);
        Response<Long> response = userFeignApi.registerUser(registerUserReqDTO);
        if (!response.isSuccess()) {
            return null;
        }
        return response.getData();
    }

    public FindByPhoneRspDTO findByPhone(String phone) {
        FindByPhoneReqDTO findByPhoneReqDTO = new FindByPhoneReqDTO();
        findByPhoneReqDTO.setPhone(phone);
        Response<FindByPhoneRspDTO> response = userFeignApi.findByPhone(findByPhoneReqDTO);
        if (!response.isSuccess()) {
            return null;
        }
        return response.getData();
    }

    public void updatePassword( String newPassword) {
        UpdatePasswordReqDTO updatePasswordReqDTO = new UpdatePasswordReqDTO();
        updatePasswordReqDTO.setNewPassword(newPassword);
        userFeignApi.updatePassword(updatePasswordReqDTO);
    }
}

